


//_______________________________________________________________________________________________________________
/****************************************************************************************************************/
/*                                                                                                              */
/*                     O L D   S T Y L E   S T A T I C   T I M E R S                                            */
/*                                                                                                              */
/*                     (not recommended to use. use STimers instead (see osa_stimers.h)                         */
/*                                                                                                              */
/****************************************************************************************************************/

//------------------------------------------------------------------------------
// Stop timer

#define OS_StopTimer(timer_id)      { OS_Timeouts[(timer_id) >> _OST_INT_SHIFT] &= ~(1 << ((timer_id) & _OST_INT_MASK)); }

//------------------------------------------------------------------------------
// Run timer (internal system macro)

#define _OS_RunTimer(timer_id)      { OS_Timeouts[(timer_id) >> _OST_INT_SHIFT] |=  (1 << ((timer_id) & _OST_INT_MASK)); }

//------------------------------------------------------------------------------
// Check for overflow

#define OS_CheckTimer(timer_id)     (!(OS_Timeouts[(timer_id) >> _OST_INT_SHIFT] & (1 << ((timer_id) & _OST_INT_MASK))))

//------------------------------------------------------------------------------
// Check for timer is running

#define OS_IsTimerRun(timer_id)     (OS_Timeouts[(timer_id) >> _OST_INT_SHIFT] & (1 << ((timer_id) & _OST_INT_MASK)))


//------------------------------------------------------------------------------
// Run 8-bit timer

#define OS_RunTimer8(timer_id, time)                                \
    {                                                               \
        OS_StopTimer(timer_id);                                     \
        OS_Timers8 [timer_id] = -(time);                            \
        _OS_RunTimer(timer_id);                                     \
    }


//------------------------------------------------------------------------------
// Run 16-bit timer

#define OS_RunTimer16(timer_id, time)                               \
    {                                                               \
        OS_StopTimer(timer_id);                                     \
        OS_Timers16[(timer_id) - _OS_TIMER16_POS] = -(time);        \
        _OS_RunTimer(timer_id);                                     \
    }

//------------------------------------------------------------------------------
// Run 24-bit timer

#define OS_RunTimer24(timer_id, time)                                       \
    {                                                                       \
        OS_StopTimer(timer_id);                                             \
        OS_Timers24[(timer_id) - _OS_TIMER24_POS] = - (((time) + 128) >> 8);\
        _OS_RunTimer(timer_id);                                             \
    }
    
//------------------------------------------------------------------------------
// Run 24-bit timer withowt recounting prescaler (not recomended to use)

#define OS_RunTimer24prs(timer_id, time)                            \
    {                                                               \
        OS_StopTimer(timer_id);                                     \
        OS_Timers24[(timer_id) - _OS_TIMER24_POS] = -(time);        \
        _OS_RunTimer(timer_id);                                     \
    }

//------------------------------------------------------------------------------
// Run 32-bit timer

#define OS_RunTimer32(timer_id, time)                               \
    {                                                               \
        OS_StopTimer(timer_id);                                     \
        OS_Timers32[(timer_id) - _OS_TIMER32_POS] = -(time);        \
        _OS_RunTimer(timer_id);                                     \
    }
//------------------------------------------------------------------------------
// Wait for timer overflowed

#define OS_WaitTimer(timer_id)                                              \
    {                                                                       \
        _OS_WAIT_EVENT(OS_CheckTimer(timer_id));                            \
    }
      
//------------------------------------------------------------------------------
// Delay current task using old style static timer
#define OS_DelayTimer8(timer_id, delay)     \
    {                                       \
        OS_RunTimer8(timer_id, delay);      \
        OS_WaitTimer(timer_id);             \
    }

//------------------------------------------------------------------------------
#define OS_DelayTimer16(timer_id, delay)    \
    {                                       \
        OS_RunTimer16(timer_id, delay);     \
        OS_WaitTimer(timer_id);             \
    }

//------------------------------------------------------------------------------
#define OS_DelayTimer24(timer_id, delay)    \
    {                                       \
        OS_RunTimer24(timer_id, delay);     \
        OS_WaitTimer(timer_id);             \
    }

//------------------------------------------------------------------------------
#define OS_DelayTimer32(timer_id, delay)    \
    {                                       \
        OS_RunTimer32(timer_id, delay);     \
        OS_WaitTimer(timer_id);             \
    }



